package com.qf.util;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.text.ParseException;

/**
 * 2019/10/8
 * Administrator
 * quartz1008
 * 面向对象面向君  不负代码不负卿
 */
public class ExecuteJob {
    //任务调度的三要素:1.任务 2.触发器 3.调度器
    public void testa(){
        try {
            //1.创建任务类Job  JobDetail(String name,Classs JobClass);
            JobDetail jobDetail=new JobDetail("我的任务1",MyJob.class);

            JobDataMap jobDataMap = new JobDataMap();
            jobDataMap.put("uname","张三");
            jobDetail.setJobDataMap(jobDataMap);//给Job传递动态数据

            //2.创建触发器  SimpleTrigger(String name, int repeatCount, long repeatInterval)
           // SimpleTrigger simpleTrigger=new SimpleTrigger("我的触发器1",-1,2000);
            CronTrigger cronTrigger=new CronTrigger("cronTrigger1","groupa","30 5 15 8 10  ? 2019");
            //3.创建调度器
            Scheduler scheduler = new StdSchedulerFactory().getScheduler();
            //4.由调度器将Job和Trigger绑定到一起
            scheduler.scheduleJob(jobDetail,cronTrigger);
            //5.启动调度器
            scheduler.start();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }catch (ParseException e){
            e.printStackTrace();
        }
    }
}
